package com.dopdxd.combase.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

/**
 * @Description: Fragment基类
 * @Author: kim
 * @CreateDate: 2024/4/8 10:29
 * @Version: 1.0
 */
abstract class BaseFragment<VB : ViewBinding>(private val inflater: (LayoutInflater, ViewGroup?, Boolean) -> VB) : Fragment() {

    private var _binding: VB? = null
    val mBinding: VB get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = inflater(inflater, container, false)
        return _binding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(savedInstanceState)
        initListener()
        subscribeData()
        loadData()
    }


    protected open fun initView(savedInstanceState: Bundle?){}

    protected open fun initListener() {}

    protected open fun subscribeData() {}

    protected open fun loadData() {}

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

}